import os;
from datetime import datetime;
import requests;

'''
BDTP storage
'''
__author__ = 'fuhaotian';

def image_local(base_folder, keyword, images):
    # 根据查询关键字存放搜索到的图片
    dict_folder = base_folder + "/" +  keyword;
    if not os.path.exists(dict_folder):
        os.mkdir(dict_folder);

    for image in images:
        print(image)
        if image:
            r = requests.get(image);
            file_name = "%s/%s.%s" % (dict_folder,
                    str(datetime.now().timestamp()).replace(".", ""), image.split(".")[-1]);
            with open(file_name, "wb") as f:
                f.write(r.content);

if __name__ == "__main__":
    image = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=265383792,2140771021&fm=26&gp=0.jpg";
    print(image.split(".")[-1])